<?php

declare (strict_types=1);

namespace app\dao\v1\recovery;

use app\dao\BaseDao;
use app\model\v1\recovery\RecoveryUserSearchHistory;

class RecoveryUserSearchHistoryDao extends BaseDao
{

    /**
     * 设置模型
     * @return string
     */
    protected function setModel(): string
    {
        return RecoveryUserSearchHistory::class;
    }


    /**
     * 添加一条用户搜索
     * @param array $data
     * @return int|string
     */
    public function createOne(array $data)
    {
        if(empty($data["uid"]) || empty($data["keyword"])) return false;

        $word_find = $this->getModel()->where("keyword", $data["keyword"])->where("uid", $data["uid"])->find();
        if(empty($word_find)){
            $data["create_time"] = time();
            $res = $this->getModel()->insertGetId($data);
        }else{
            $this->getModel()->where("id", $word_find["id"])->update(["update_time"=>time()]);
            $res = 1;
        }

        return $res;
    }


}